package com.stujyh.spring6;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class TimerInvocationHandler implements InvocationHandler {
    private OrderDao target;

    public TimerInvocationHandler() {
    }

    public TimerInvocationHandler(OrderDao target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //增强代码
        Long begin = System.currentTimeMillis();
        Object res = method.invoke(target,args);
        Long end = System.currentTimeMillis();
        System.out.println("方法耗时：" + (end - begin) + "秒");
        return res;
    }
}
